package site.yunnong.atvris.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import site.yunnong.atvris.dao.domain.VideoProfile;
import site.yunnong.atvris.dao.domain.VideoProfileExample;
import site.yunnong.atvris.dao.mapper.VideoProfileMapper;
import site.yunnong.atvris.service.VideoProfileService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 视频统计信息
 *
 * @author zhangjinghao
 * @email jhzhang9102@163.com
 * @date 2021-07-09 23:45:37
 */
@Slf4j
@Service
public class VideoProfileServiceImpl implements VideoProfileService {

    @Resource
    private VideoProfileMapper videoProfileMapper;

    @Override
    public int insert(VideoProfile videoProfile) {
        return videoProfileMapper.insertSelective(videoProfile);
    }

    @Override
    public VideoProfile queryByUvid(Long uvid) {
        VideoProfileExample example = new VideoProfileExample();
        example.createCriteria().andUvidEqualTo(uvid);
        List<VideoProfile> profileList = videoProfileMapper.selectByExample(example);
        if (CollectionUtils.isNotEmpty(profileList)) {
            return profileList.get(0);
        }
        return null;
    }

    @Override
    public List<VideoProfile> queryAll() {
        return videoProfileMapper.selectByExample(new VideoProfileExample());        
    }

    @Override
    public int updateVideoProfile(VideoProfile videoProfile) {
        log.info("VideoProfileServiceImpl.updateVideoProfile, videoProfile: {}", videoProfile);
        VideoProfileExample example = new VideoProfileExample();
        VideoProfileExample.Criteria criteria = example.createCriteria();
        if (videoProfile.getId() != null) {
           criteria.andIdEqualTo(videoProfile.getId());
        }
        if (videoProfile.getUvid() != null) {
            criteria.andUvidEqualTo(videoProfile.getUvid());
        }
        int count = videoProfileMapper.updateByExampleSelective(videoProfile, example);
        log.info("VideoProfileServiceImpl.updateVideoProfile, videoProfile: {}, result: {}", videoProfile, count);
        return count;
    }
}

